<template>
	<view class="mainpadding2">
		<view class="mainpadding_top ffffff radius flexleft" v-for="item in list.data" :key="item.id" @click="jumpzhuye(item.id)">
			<image :src="item.avatar_text" class="headimg margin_right3" mode=""></image>
			<view class="">
				<view class="flexleft">
					<view class="sanshier xiaohei bold margin_right3">{{item.nickname}}</view>
					<view class="sexbox flexleft" style="background-color: #e5f4ff;" v-if="item.gender==0">
						<image src="@/static/image/system/boy.png" mode=""></image>
						<view class="" style="color: #0077FF;">{{item.age || ""}}</view>
					</view>
					<view class="sexbox flexleft" style="background-color: #fff0f0;" v-if="item.gender==1">
						<image src="@/static/image/system/gril.png" mode=""></image>
						<view class="" style="color: #ff9494;">{{item.age}}</view>
					</view>
				</view>
				<view class="flexleft flex-wrap">
					<view class="xlbtn flexcenter margin_top margin_right1" v-if="item.online">
						<view class="smalltext xiaohui" style="color: #0077FF;">在线</view>
					</view>
					<view class="xhbtn flexcenter margin_top margin_right1" v-if="ind==1 || ind==2" v-for="(ite,ind) in item.user_flag_names" :key="ite">
						<view class="smalltext xiaohui">{{ite}}</view>
					</view>
					<view class="xhbtn flexcenter margin_top">
						<view class="smalltext xiaohui">{{returnKmUnit(Number(item.distance))}}</view>
					</view>
				</view>
				<view class="xiaohei margin_top strongtext xiankuan" v-if="item.bio">{{item.bio}}</view>
				<view class="xiaohei margin_top strongtext xiankuan" v-if="!item.bio">这个人很懒，还未留下任何信息...</view>
			</view>
		</view>
		<yk-authpup ref="authpup" type="top" @changeAuth="changeAuth" :permissionID="permissionID"></yk-authpup>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				latitude: "",
				longitude: "",
				permissionID: '',
			}
		},
		onLoad() {
			// #ifdef APP-PLUS
			this.getlocationFn()
			// #endif
			// #ifdef H5
			this.init()
			// #endif
		},
		methods: {
			changeAuth() {
				let _this = this
				uni.showLoading({
					mask:true,
					title:"获取定位中"
				})
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						uni.hideLoading()
						_this.latitude = res.latitude
						_this.longitude = res.longitude
						_this.init()
						_this.setuserlat()
					},
					fail(err) {
						_this.openAuthSetting();
					}
				});
			},
			getlocationFn() {
				let _this = this
				if (uni.getSystemInfoSync().brand.toLowerCase() === 'huawei') {
					this.permissionID = 'ACCESS_FINE_LOCATION';//这个是对应的权限 ACCESS_FINE_LOCATION 位置权限 / WRITE_EXTERNAL_STORAGE 存储空间/照片权限 / CAMERA相机权限 / CALL_PHONE 拨打电话
					setTimeout(()=>{
						this.$refs['authpup'].open();
					},500)
					return false
				}
				uni.showLoading({
					mask:true,
					title:"获取定位中"
				})
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						uni.hideLoading()
						_this.latitude = res.latitude
						_this.longitude = res.longitude
						_this.init()
						_this.setuserlat()
					},
					fail(err) {
						uni.hideLoading()
						_this.openAuthSetting();
					}
				});
			},
			setuserlat(){
				httpRequest.request('/api/user/profile', 'GET', {latitude:this.latitude,longitude:this.longitude,}).then(res => {})
			},
			init(isPage, page) {
				let _this = this;
				uni.showLoading({
					mask:true,
					title:"请稍后"
				})
				let data = {
					page: page || 1,
					limit: _this.limit,
					lat: this.latitude,
					lng: this.longitude,
				}
				console.log("定位",data)
				let url = '/api/user/fjUser'
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							this.list = res.data
							_this.list.data = resList.data;
						}
					}
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},

		}
	}
</script>

<style lang="scss" scoped>
	
	page{
		background-color: #f8f8f8;
	}
	.headimg {
		width: 130rpx;
		height: 130rpx;
		border-radius: 50%;
		min-width: 130rpx;
	}

	.xhbtn {
		padding: 10rpx 20rpx;
		background: #F5F5F5;
		border-radius: 50rpx;
	}

	.sexbox {
		padding: 5rpx 10rpx;
		border-radius: 50rpx;
		font-size: 16rpx;
		font-weight: bold;

		image {
			width: 24rpx;
			height: 24rpx;
		}
	}

	.xlbtn {
		padding: 10rpx 20rpx;
		background: #e5f4ff;
		border-radius: 50rpx;
	}
</style>